import {
	uniRouter
} from "./router"
// import {
// 	getUserInfoData
// } from "../api/api.js"
import {
	uniStorage
} from "./storage"
import {
	uniToast
} from "./toast"

export function wxlogin() {
	return new Promise((reslove, reject) => {
		uni.login({
			provider: 'weixin',
			onlyAuthorize:true,
			success(res) {
				console.log(res)
				reslove(res.code)
			},
			fail(err) {
				reject(err)
			}
		})
	})
}

export function isHasPhone() {

	return new Promise((l, r) => {
		const userInfo = uniStorage.getValue("userInfo")
		let isHas = false
		console.log("isHasPhone", userInfo)
		if (userInfo?.phoneNumber) {
			isHas = true
			l(isHas)
		} else {
			uniRouter.setPath()
			uniRouter.relaunchTo("/pages/login/login")
			l(isHas)
		}
	})

}


// export function getUserInfo() {
// 	return new Promise(async (reslove, reject) => {
// 		try {
// 			let partyId = uniStorage.getValue('partyId')
// 			console.log("partyId", partyId)
// 			getUserInfoData({
// 				partyId: partyId
// 			}).then(res => {
// 				console.log(res)
// 				uniStorage.save('userInfo', res.data)
// 				reslove(res.data)
// 			})


// 		} catch (e) {
// 			console.log(e)
// 			uniToast.toast("请检查网络或重新登录!")
// 			uniRouter.setPath()
// 			uniRouter.relaunchTo('/pages/login/index')
// 			reject(e)
// 		}
// 	})
// }